package com.dayuanit.dy15.atm.service.impl;

import com.dayuanit.dy15.atm.dto.WebSocketMessageDTO;
import com.dayuanit.dy15.atm.entity.WebSocketMessage;
import com.dayuanit.dy15.atm.mapper.WebSocketMessageMapper;
import com.dayuanit.dy15.atm.service.MessageService;
import com.dayuanit.dy15.atm.util.MoneyUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class MessageServiceImpl implements MessageService {

    @Autowired
    private WebSocketMessageMapper webSocketMessageMapper;

    @Override
    public WebSocketMessageDTO saveMessage(int type, String message, long userId, String amount) {
        WebSocketMessage webSocketMessage = new WebSocketMessage();
        webSocketMessage.setCreateTime(new Date());
        webSocketMessage.setMessage(message);
        webSocketMessage.setModifyTime(webSocketMessage.getCreateTime());
        webSocketMessage.setMsgType(1);
        webSocketMessage.setStatus(1);
        webSocketMessage.setUserId(userId);
        webSocketMessageMapper.insert(webSocketMessage);

        WebSocketMessageDTO dto = new WebSocketMessageDTO();
        dto.setCreateTime(webSocketMessage.getCreateTime().getTime());
        dto.setId(webSocketMessage.getId());
        dto.setMessage(message);
        dto.setMsgType(webSocketMessage.getMsgType());
        dto.setStatus(webSocketMessage.getStatus());
        dto.setUserId(userId);
        dto.setAmount(amount);
        return dto;
    }
}
